package com.ewanghuiju.app.ui.my.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.RootActivity;
import com.ewanghuiju.app.base.contract.my.MyContract;
import com.ewanghuiju.app.model.bean.local.TabEntity;
import com.ewanghuiju.app.model.bean.response.LbImgBean;
import com.ewanghuiju.app.model.bean.response.OrderStatusResponBean;
import com.ewanghuiju.app.model.bean.response.UserInfoResponBean;
import com.ewanghuiju.app.model.bean.response.VersionResponBean;
import com.ewanghuiju.app.model.http.response.BaseResponse;
import com.ewanghuiju.app.presenter.my.MyPresenter;
import com.ewanghuiju.app.ui.main.adapter.MyPagerAdapter;
import com.ewanghuiju.app.ui.my.adapter.WalletBillListAdapter;
import com.ewanghuiju.app.ui.my.fragment.WalletCenterFragment;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.List;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 钱包中心页面
 * @time 2020/2/24
 */
public class WalletCenterActivity extends RootActivity<MyPresenter> implements MyContract.View {
    @BindView(R.id.commonTabLayout)
    CommonTabLayout commonTabLayout;
    //    @BindView(R.id.tv_classify)
//    TextView tvClassify;
//    @BindView(R.id.tv_date)
//    TextView tvDate;
    @BindView(R.id.viewpage)
    ViewPager viewpage;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    @BindView(R.id.tv_wallet_balance)
    TextView tvWalletBalance;


    private ArrayList<CustomTabEntity> mTabEntities;

    private WalletBillListAdapter adapter;


    private List<Fragment> fragmentList;

    @Override
    protected int getLayout() {
        return R.layout.activity_wallet_center;
    }

    @Override
    protected void initEventAndData() {

        mToolbar.setBackground(null);
        mToolbar.setNavigationIcon(R.mipmap.icon_fan_white);
        tvTitle.setTextColor(ContextCompat.getColor(mContext, R.color.white));
        tvTitleRight.setVisibility(View.VISIBLE);

        initCommonTabLayout();
        //获取用户信息
        mPresenter.getData();
    }

    private void initCommonTabLayout() {
        fragmentList = new ArrayList<>();
        mTabEntities = new ArrayList<>();
        mTabEntities.add(new TabEntity("收入", R.mipmap.icon_selected_tab, 0));
        mTabEntities.add(new TabEntity("支出", R.mipmap.icon_selected_tab, 0));
        commonTabLayout.setTabData(mTabEntities);

        List<String> childStrList = new ArrayList<>();
        childStrList.add("收入");
        childStrList.add("支出");

        WalletCenterFragment srFragment = new WalletCenterFragment();
        Bundle srBundle = new Bundle();
        srBundle.putInt(Constants.WALLETCENTER_TYPE, 1);
        srFragment.setArguments(srBundle);
        fragmentList.add(srFragment);

        WalletCenterFragment zcFragment = new WalletCenterFragment();
        Bundle zcBundle = new Bundle();
        zcBundle.putInt(Constants.WALLETCENTER_TYPE, 2);
        zcFragment.setArguments(zcBundle);
        fragmentList.add(zcFragment);

        viewpage.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), 0, fragmentList, childStrList));
        commonTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewpage.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {
            }
        });

        viewpage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                commonTabLayout.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        viewpage.setCurrentItem(0);
    }


//    @Override
//    protected void intSmartRefreshLayout() {
//        refreshLayout.setEnableRefresh(true);//是否启用下拉刷新功能
//        refreshLayout.setEnableLoadMore(false);//是否启用上拉加载功能
//        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
//            @Override
//            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
//                refreshLayout.finishRefresh(3000);
//                adapter.setNewData(TestBean.getBillListResponBeanBeanList(10));
//            }
//        });
//    }


    @OnClick({R.id.tv_to_deposit, R.id.tv_title_right})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_title_right:
                //去提现
                new StartActivityUtil(mContext, WalletCashActivity.class).startActivity(true);
                break;
            case R.id.tv_to_deposit:
                //去充值
                new StartActivityUtil(mContext, WalletRechargeActivity.class).startActivity(true);
                break;
            default:
                break;
        }
    }


    @Override
    protected int getTitleIntText() {
        return R.string.wallet_title;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(mToolbar, true)
                .init();
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    public void showContent(String list) {

    }

    @Override
    public void showUserInfo(UserInfoResponBean bean) {
        if (bean != null) {
            tvWalletBalance.setText(bean.getBalance());
        }
    }

    @Override
    public void showUserInfoError() {

    }

    @Override
    public void settingAvaterSuccess() {

    }

    @Override
    public void bindWxSuccess() {

    }

    @Override
    public void unBindWxSuccess() {

    }

    @Override
    public void showOsstoken(BaseResponse baseResponse) {

    }

    @Override
    public void showLbImg(int type, List<LbImgBean> list) {

    }

    @Override
    public void showUpgradeInfo(VersionResponBean versionResponBean) {

    }

    @Override
    public void showPtiorderStatus(OrderStatusResponBean orderStatusResponBean) {

    }
}
